package com.wjd.wshow.common.resource.entity;

import com.wjd.wshow.common.resource.AbstractResource;
import com.wjd.wshow.common.resource.ResourceType;
import com.wjd.wshow.entity.ResourceEntity;

import java.nio.file.Path;
import java.nio.file.Paths;

public class EntityResource<T extends ResourceEntity> extends AbstractResource {

    protected T entity;

    public EntityResource() {}

    public EntityResource(T entity) {
        this.entity = entity;
    }

    public T getEntity() {
        return entity;
    }

    public void setEntity(T entity) {
        this.entity = entity;
    }

    @Override
    public String getResId() {
        if (entity == null) {
            return null;
        }
        return entity.getId();
    }

    @Override
    public ResourceType getType() {
        return entity.getResourceType();
    }

    @Override
    public Path getPath() {
        Path path;
        if (entity == null) {
            return null;
        }
        path = Paths.get(entity.getPath());
        return path;
    }
}
